﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

using ProjectCommon2.Wcf.MessageHeaders;
using ProjectCommon2.Wcf.Attributes;
using PolePosition.v3.EntityLibrary;
using PolePosition.v3.EntityFactory;
using System.Data;
using System.IO;

using System.ServiceModel.Web;
using System.Drawing;

namespace PolePosition.v3.WcfService
{
    [ServiceContract]
    public class Resources
    {
        [OperationContract]
        [WebGet(UriTemplate = "Image/{id}/{height}/{width}")]
        public Stream Image(int id, int height, int width)
        {
            MemoryStream _MemoryStream = new MemoryStream();
            v3.WcfService.Properties.Resources.flag_c.Save(
                _MemoryStream, System.Drawing.Imaging.ImageFormat.Gif);
            WebOperationContext.Current.OutgoingResponse.ContentType = "image/gif";
            return _MemoryStream;
        }

        [OperationContract]
        [WebGet(UriTemplate = "Icon/{id}")]
        public Stream Icon(int id)
        {
            MemoryStream _MemoryStream = new MemoryStream();
            v3.WcfService.Properties.Resources.flag_h.Save(
                _MemoryStream, System.Drawing.Imaging.ImageFormat.Gif);
            WebOperationContext.Current.OutgoingResponse.ContentType = "image/gif";
            return _MemoryStream;
        }

        [OperationContract]
        [WebGet]
        public System.IO.Stream GetImage()
        {
            Bitmap bitmap = new Bitmap(20, 20);
            for (int i = 0; i < bitmap.Width; i++)
                for (int j = 0; j < bitmap.Height; j++)
                    bitmap.SetPixel(i, j, (Math.Abs(i - j) < 2) ? Color.Blue : Color.Yellow);
            MemoryStream ms = new MemoryStream();
            bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            ms.Position = 0;
            WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
            return ms;
        }
    }
}
